<?

//Data loading
$title='FAKTUR PAJAK STANDAR';
$title2='';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI TATANAN CONTAINER';
$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ();
$pdf->GridTable($Result);
$pdf->Output();

function GridList () {
    global $DBConnection, $DBName2;
    $SQL = "SELECT ledger FROM tblcoa ORDER BY ledger DESC LIMIT 1";
    $FLedger = $DBConnection->dbc->get_var($SQL);

    //$DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
  $SQL  = "SELECT ais_receipt.*,UNIX_TIMESTAMP(tglkwit) as tglkwit FROM ais_receipt ";
  $SQL .= "INNER JOIN tblreceipt ON tblreceipt.kdreceipt=ais_receipt.thbl ";
  $SQL .= "INNER JOIN tblcoa ON tblreceipt.skada=tblcoa.skada AND tblcoa.inc_ppn=1 AND tblcoa.ledger='$FLedger' ";
  $SQL .= "WHERE nokwit='".GetParam("nokwit","")."' ORDER BY urut ";
//  die($SQL);
  return $DBConnection->dbc->get_results($SQL,ARRAY_A);
}

function ReadHeader ($nokwit) {
    global $DBConnection, $DBName2;
    //$DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
  $SQL  = "SELECT ais_receipt.* FROM ais_receipt ";
  $SQL .= "WHERE nokwit='".$nokwit."' LIMIT 1 ";

  return $DBConnection->dbc->get_row($SQL);
}

function ReadPengusaha() {
  global $DBConnection,$DBGeneral;
  $SQL = "SELECT *,UNIX_TIMESTAMP(pakwtpkp_tax) as pakwtpkp_tax  FROM $DBGeneral.tblcompany ";
  return $DBConnection->dbc->get_row($SQL);
}

function ReadPembeli($debturCode) {
    global $DBConnection, $DBGeneral,$DBName;
  $SQL = "SELECT * FROM $DBName.tbldebtur WHERE CUCODE='".$debturCode."' ";
//  print $SQL;
  return $DBConnection->dbc->get_row($SQL);
}

function ReadVatDate($nokwit) {
    global $DBConnection, $DBGeneral,$DBName;
  $SQL = "SELECT tglvat FROM ais_receipt WHERE nokwit='$nokwit' ";
  return $DBConnection->dbc->get_var($SQL);
}

$paramo = GetParam("nokwit","");
//$FieldPembeli = ReadPembeli($DBConnection->dbc->get_var($SQL));
 $test = ReadVatDate($paramo);
 echo "$test"; exit;

class PDFReport extends PDF {
        var $coordX = 0;
        var $coordY = 0;

    function Header() {
        global $title,$title2,$perush,$page,$DEFINE_FONT,$DBConnection;
        if ($DEFINE_FONT==0) {
            $this->AddFont('Arial','','arialn.php');
            $DEFINE_FONT=1;
        }

    $Field = ReadHeader(GetParam("nokwit",""));
    $this->spell_date = strtoupper($Field->spell_date);
    list($this->year,$this->month,$this->day) = explode("-",$Field->tglbkt);

    $this->SetFont('Arial','',11);
    $this->SetLeftMargin(5);
    $this->Cell(200,7,"",0,1,'L',0);
    //$this->Ln();$this->Ln();
    $this->Cell(160,5,"",0,0,'L',0);
    $this->Cell(40,5,"",0,1,'L',0);
    $this->Cell(160,5,"",0,0,'L',0);
    $this->Cell(40,5,"",0,1,'L',0);
    $this->Cell(50,7,"",0,0,'L',0);
    $this->SetFont('Arial','',16);
    if (strlen(trim($Field->npwp))==0) $title = "FAKTUR PAJAK SEDERHANA";
    $this->Cell(105,7,$title,0,0,'C',0);
    $this->SetFont('Arial','',11);

        /*
    $this->Cell(50,7,"",0,1,'L',0);
    $this->Cell(155,7,"",0,0,'C',0);
    $this->Cell(50,7,"",0,1,'L',0);
    */

    $this->Ln();
    $this->SetLeftMargin(5);
    //$this->Line(5,30,210,30);
    $this->Cell(205,7,"Kode dan Nomor Seri Faktur Pajak : ".$Field->faktur,1,0,'L',0);
    $this->Ln();
    $FieldPengusaha = ReadPengusaha();
    $this->Cell(205,7,"PENGUSAHA KENA PAJAK","LTR",1,'L',0);

    //$this->Cell(205,5,"Nama","LR",1,'L',0);
    $this->Cell(35,5,"Nama","L",0,'L',0);$this->Cell(170,5,": ".$FieldPengusaha->papers_tax,"R",1,'L',0);
    //$this->Cell(35,5,"Alamat","L",0,'L',0);$this->Cell(170,5,": ".$FieldPengusaha->paaddr_tax.", ".$FieldPengusaha->paaddr_tax2,"R",1,'L',0);
    $this->Cell(35,5,"Alamat","L",0,'L',0);$this->Cell(170,5,": ".$FieldPengusaha->paaddr_tax,"R",1,'L',0);
    $this->Cell(35,5,"NPWP","L",0,'L',0);
    $this->Cell(3,5,": ","",0,'L',0);

//Begin NPWP
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,0,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,1,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,2,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,3,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,4,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,5,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,6,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,7,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,8,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,9,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,10,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,11,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,12,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,13,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPengusaha->pakwtnpwp_tax ,14,1),1,0,'C',0);
    $this->Cell(112,5,"","R",0,'R',0);
//End NPWP

    $this->Ln();
    $this->Cell(35,5,"Tanggal Pengukuhan PKP","L",0,'L',0);$this->Cell(170,5,": ".strtoupper(IndonesianDate("j F Y",$FieldPengusaha->pakwtpkp_tax)),"R",1,'L',0);

    $SQL = "SELECT debtur FROM ais_receipt WHERE nokwit='".GetParam("nokwit","")."' ";
    $FieldPembeli = ReadPembeli($DBConnection->dbc->get_var($SQL));

    $this->Cell(205,7,"PEMBELI BARANG KENA PAJAK/PENERIMA JASA KENA PAJAK","LTR",1,'L',0);
    $this->Cell(35,5,"Nama","L",0,'L',0);$this->Cell(170,5,": ".$FieldPembeli->CUNAME,"R",1,'L',0);
    $this->Cell(35,5,"Alamat","L",0,'L',0);
    $this->SetFont('Arial','',9);
    $this->Cell(170,5,": ".$FieldPembeli->CUADDR,"R",1,'L',0);
    $this->SetFont('Arial','',11);
    $this->Cell(35,5,"NPWP","L",0,'L',0);$this->Cell(3,5,": ","",0,'L',0);

//Begin NPWP
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,0,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,1,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,2,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,3,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,4,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,5,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,6,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,7,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,8,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,9,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,10,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,11,1),1,0,'C',0);
    $this->Cell(2,5,"","LR",0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,12,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,13,1),1,0,'C',0);
    $this->Cell(3,5,substr($FieldPembeli->CUNPWP,14,1),1,0,'C',0);
    $this->Cell(10,5,"",0,0,'C',0);
    $this->Cell(10,5,"NPPKP",0,0,'C',0);
    $this->Cell(2,5,"","R",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{0},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{1},1,0,'C',0);
    $this->Cell(2,5,"","R",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{2},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{3},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{4},1,0,'C',0);
    $this->Cell(2,5,"","",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{5},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{6},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{7},1,0,'C',0);
    $this->Cell(2,5,"","",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{8},1,0,'C',0);
    $this->Cell(2,5,"","",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{9},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{10},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{11},1,0,'C',0);
    $this->Cell(2,5,"","",0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{12},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{13},1,0,'C',0);
    $this->Cell(3,5,$FieldPembeli->CUNPPKP{14},1,0,'C',0);
      $this->Cell(35,5,"","R",0,'R',0);
//End NPWP
    $this->Ln();
    $this->Cell(205,5,"","LBR",1,'L',0);
    $this->Cell(10,7,"No.",1,0,'C',0);
    $this->Cell(100,7,"Nama Barang/Jasa Kena Pajak",1,0,'C',0);
    $this->Cell(95,7,"Harga Jual / Penggantian / Uang Muka / Termijn (IDR)",1,0,'C',0);
    $this->Ln();
/*
        $this->Cell(10,7,"","LR",0,'C',0);
        $this->Cell(100,7,"","LR",0,'C',0);
        $this->Cell(95,7,"","LR",0,'C',0);
        $this->Ln();
*/
    //Header
    //Column widths
    }

    function GridTable($MyResult) {
        //Column widths
        global $DBConnection;
        $w=array(15,120,20,50);
        $RowSize = 15;
        //Data
        if ($MyResult)
        foreach($MyResult as $row)
        {
                $Total = $Total + $row["jumlah"];
                $n++;
                $tglkwit = $row["tglkwit"];
                $this->Cell(10,5,$n.".","LR",0,'R',0);
                $this->Cell(100,5,$row["uraian"],"LR",0,'L',0);
                $this->Cell(95,5,FormatNumber($row["jumlah"]),"LR",0,'R',0);
                if (strlen($row["container_no"])) {
                    $this->Ln();
                    $this->Cell(10,5,"","LR",0,'R',0);
                    $this->Cell(100,5,$row["container_no"],"LR",0,'L',0);
                    $this->Cell(95,5,"","LR",0,'R',0);
                }
                $this->Ln();
        }
            $this->Cell(10,5,"","LR",0,'R',0);
            $this->Cell(100,5,"Nomor Kwitansi: ".GetParam("nokwit",""),"LR",0,'L',0);
            $this->Cell(95,5,"","LR",0,'R',0);
            $this->Ln();
            $RowSpace = $RowSize - $n - 1;
            for ($x=1;$x<=$RowSpace;$x++) {
                $this->Cell(10,5,"","LR",0,'C',0);
                $this->Cell(100,5,"","LR",0,'C',0);
                $this->Cell(95,5,"","LR",0,'C',0);
                $this->Ln();
            }
                        $this->coordX = $this->GetX();
                        $this->coordY = $this->GetY();
            $this->Cell(110,7,"Jumlah Harga Jual / Penggantian / Uang Muka / Termijn *)",1,0,'L',0);
            $this->Cell(95,7,FormatNumber($Total),1,0,'R',0);
            $this->Ln();
            $this->Cell(110,7,"Dikurangi potongan harga",1,0,'L',0);
            $this->Cell(95,7,"",1,0,'C',0);
            $this->Ln();
            $this->Cell(110,7,"Dikurangi uang muka yang telah diterima",1,0,'L',0);
            $this->Cell(95,7,"",1,0,'C',0);
            $this->Ln();
            $this->Cell(110,7,"Dasar Pengenaan Pajak",1,0,'L',0);
            $this->Cell(95,7,FormatNumber($Total),1,0,'R',0);
            $this->Ln();
            $this->Cell(110,7,"PPN : 10% X Dasar Pengenaan Pajak",1,0,'L',0);
            $this->Cell(95,7,FormatNumber($Total*10/100),1,0,'R',0);
            $this->Ln();
            $this->Cell(110,5,"","LT",0,'L',0);
            $this->Cell(95,5,"","TR",0,'R',0);
            $this->Ln();
            $this->Cell(5,5,"","LR",0,'L',0);
            $this->Cell(15,5,"TARIF","LTRB",0,'C',0);
            $this->Cell(35,5,"DPP","LTRB",0,'C',0);
            $this->Cell(35,5,"PPn BM","LTRB",0,'C',0);

            $paramo = GetParam("nokwit","");
            $tglvat = ReadVatDate($paramo);
            $rama = IndonesianDate2($tglvat);
            //echo "$rama"; exit;
            //echo "kozhie : $tglvat"; exit;

            $this->Cell(115,5,GetBranchName().", ".strtoupper(IndonesianDate2($tglvat)),"LR",0,'C',0);
            $this->Ln();
            $this->Cell(5,5,"","LR",0,'L',0);
            $this->Cell(15,5,"....... %","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(115,5,"","LR",0,'C',0);
            $this->Ln();
            $this->Cell(5,5,"","LR",0,'L',0);
            $this->Cell(15,5,"....... %","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(115,5,"","LR",0,'C',0);
            $this->Ln();
            $this->Cell(5,5,"","LR",0,'L',0);
            $this->Cell(15,5,"....... %","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LR",0,'C',0);
            $this->Cell(115,5,"","LR",0,'C',0);
            $this->Ln();
            $this->Cell(5,5,"","L",0,'L',0);
            $this->Cell(15,5,"JUMLAH","LTB",0,'C',0);
            $this->Cell(35,5,"","RTB",0,'C',0);
            $this->Cell(35,5,"Rp. ............................","LRTB",0,'C',0);

            $SQL = "SELECT * FROM tblprofile ";
            $Field = $DBConnection->dbc->get_row($SQL);

            $this->Cell(115,5,"( ".$Field->ttdkw." )","LR",0,'C',0);
            $this->Ln();
            $this->Cell(90,2,"","L",0,'L',0);
            $this->Cell(115,2,"---------------------","R",0,'C',0);
            $this->Ln();
            $this->Cell(90,5,"","LB",0,'L',0);
            $this->Cell(115,5,"".$Field->jabtax."","BR",0,'C',0);
            $this->Ln();


        //Closure line
    }

    function Footer() {
        //Closure line
            $this->Cell(205,7,"*) Coret yang tidak perlu","",0,'L',0);
                        // Update By Chandra
                        $this->SetLineWidth(1);
                        $y = $this->coordY + 3.5;
                        switch(GetParam('cashType','')){
                            case 1:
                             $this->Line($this->coordX+30,$y,$this->coordX+79,$y);
                             break;
                            case 2:
                             $this->Line($this->coordX+13,$y,$this->coordX+27,$y);
                             $this->Line($this->coordX+52,$y,$this->coordX+79,$y);
                             break;
                            case 3:
                             $this->Line($this->coordX+13,$y,$this->coordX+47,$y);
                             $this->Line($this->coordX+70,$y,$this->coordX+79,$y);
                             break;
                            case 4:
                             $this->Line($this->coordX+13,$y,$this->coordX+67,$y);
                             break;
                        }

    }

}
?>
